/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package xnull;

import dep.rightClickmenu;
import dep.DataBase;
import dep.f0ntl0ader;
import com.alee.extended.window.ComponentMoveAdapter;
import com.alee.laf.rootpane.WebFrame;
import com.alee.managers.hotkey.ButtonHotkeyRunnable;
import com.alee.managers.hotkey.Hotkey;
import com.alee.managers.hotkey.HotkeyManager;
import com.alee.managers.tooltip.TooltipManager;
import com.alee.managers.tooltip.TooltipWay;
import java.awt.Font;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.TreeSet;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JTextField;

/**
 *
 * @author xyBerWise
 */
public class EnSiDictionary extends WebFrame {

    private Font nFont;
    private DataBase ff;

    /**
     * Creates new form EnSiDictionary
     */
    public EnSiDictionary() {
        initComponents();
        Cinit();
    }

    @SuppressWarnings("empty-statement")
    public final void Cinit() {
        this.setShowMaximizeButton(false);
        ComponentMoveAdapter.install(this);
        Toolkit.getDefaultToolkit().getSystemEventQueue().push(new rightClickmenu());
        atc.setSelected(false);
        //TooltipManager.setTooltip(enword_l, null, "English Word", TooltipWay.leading, 0);
        TooltipManager.setTooltip(enword_ty, null, "Type in the English Word", TooltipWay.down, 0);
        TooltipManager.setTooltip(ensi_re, null, "Corresponding Sinhala Words", TooltipWay.down, 500);
        TooltipManager.setTooltip(atc, null, "Complete Word Automatically when you Typed it in", TooltipWay.leading, 300);
        HotkeyManager.registerHotkey(this, jButton1, Hotkey.CTRL_S, new ButtonHotkeyRunnable(jButton1, 50), TooltipWay.trailing);
        TooltipManager.setTooltip(jButton1, "Press to Find", TooltipWay.down, 100);
        f0ntl0ader nF = f0ntl0ader.getInstence();
        nFont = nF.getFont("kandyunicode.ttf").deriveFont(Font.PLAIN, 18f);;
        ensi_re.setFont(nFont);
        ff = DataBase.getInstence();
        ff.sqliteConnect();

        //jLabel1(WebLabel).setMargin ( 4 );
//        TooltipManager.addTooltip ( tip, "Upper tooltip", TooltipWay.up, 0 );
//        TooltipManager.addTooltip ( tip, "Leading tooltip", TooltipWay.leading, 0 );
//        TooltipManager.addTooltip ( tip, "Trailing tooltip", TooltipWay.trailing, 0 );
//        TooltipManager.addTooltip ( tip, "Lower tooltip", TooltipWay.down, 0 );
//        
//        final WebButton tip = new WebButton ( "Tooltip with hotkey", loadIcon ( "web.png" ) );
//        HotkeyManager.registerHotkey ( owner, tip, Hotkey.CTRL_S, new ButtonHotkeyRunnable ( tip, 50 ), TooltipWay.trailing );
//        TooltipManager.setTooltip ( tip, "Increase counter", TooltipWay.trailing, 0 );
//        tip.addActionListener ( new ActionListener ()
//        {
//            private int count = 0;
//
//            public void actionPerformed ( ActionEvent e )
//            {
//                count++;
//                tip.setText ( "Pressed " + count + ( count == 1 ? " time" : " times" ) );
//            }
//        } );
//        WebLabel tip = new WebLabel ( "Default " + TooltipManager.getDefaultDelay () + "ms delay", loadIcon ( "web.png" ) );
//        TooltipManager.setTooltip ( tip, "Delayed custom tooltip", TooltipWay.trailing );
//         String tipText = "Swing " + ToolTipManager.sharedInstance ().getInitialDelay () + "ms delay tooltip";
//        WebLabel tip = new WebLabel ( tipText, loadIcon ( "swing.png" ) );
//        tip.setToolTipText ( "Delayed swing tooltip" );
    }

    public void setDatatoJlist(JList jList, ArrayList<Object> data) {

        TreeSet values = new TreeSet();
        values.clear();
        DefaultListModel model = new DefaultListModel();
        for (int i = 0; i < data.size(); i++) {
            values.add(data.get(i));
        }
        Iterator it = values.iterator();
        while (it.hasNext()) {
            model.addElement(it.next().toString());
        }
        jList.setModel(model);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        enword_l = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        enword_ty = new com.jidesoft.swing.AutoCompletionComboBox();
        atc = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ensi_re = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("English -> Sinhala Meaning");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        enword_l.setText("English Word : ");
        getContentPane().add(enword_l, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 80, 90, 20));

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        jButton3.setText("Settings");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton3);

        jButton2.setText("About");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jButton4.setText("Updates");
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton4);

        getContentPane().add(jToolBar1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 530, 30));

        enword_ty.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                enword_tyMouseReleased(evt);
            }
        });
        getContentPane().add(enword_ty, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 80, 280, -1));

        atc.setForeground(new java.awt.Color(0, 204, 204));
        atc.setText("auto-complete");
        atc.setOpaque(false);
        atc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atcActionPerformed(evt);
            }
        });
        getContentPane().add(atc, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 50, -1, -1));

        jLabel1.setText("<html>Corresponding Sinhala Words :");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 120, 80, -1));

        jButton1.setText("Find");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 80, -1, -1));

        jLabel3.setForeground(new java.awt.Color(0, 204, 204));
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 360, 90, 20));

        ensi_re.setColumns(20);
        ensi_re.setRows(5);
        jScrollPane2.setViewportView(ensi_re);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 120, 280, 240));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/0bg.png"))); // NOI18N
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 540, 440));

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        setSize(new java.awt.Dimension(544, 489));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void atcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atcActionPerformed
        if (atc.isSelected()) {
            enword_ty.setStrict(true);
        } else {
            enword_ty.setStrict(false);
        }
    }//GEN-LAST:event_atcActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Object ty_txt = ((JTextField) enword_ty.getEditor().getEditorComponent()).getText();
        if (ty_txt == null || ty_txt.toString().isEmpty()) {
        } else {
            if (enword_ty.getSelectedIndex() == 0) {
            } else {
                int y = ff.DatatoText(enword_ty.getSelectedItem().toString(), ensi_re);
                jLabel3.setText("" + y + " - records !");
            }
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void enword_tyMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_enword_tyMouseReleased
    }//GEN-LAST:event_enword_tyMouseReleased

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        new AboUt(this, true).setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        new Updates(this, true).setVisible(true);
    }//GEN-LAST:event_jButton4ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EnSiDictionary.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EnSiDictionary.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EnSiDictionary.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EnSiDictionary.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new EnSiDictionary().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton atc;
    private javax.swing.JTextArea ensi_re;
    private javax.swing.JLabel enword_l;
    private com.jidesoft.swing.AutoCompletionComboBox enword_ty;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
